//
//  SpotImageCell.m
//  hai游～
//
//  Created by jakf_17 on 15/5/23.
//  Copyright (c) 2015年 jakf_17. All rights reserved.
//

#import "SpotImageCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
@implementation SpotImageCell



- (void)dealloc
{
    [_buttomLabel release];
    [_label release];
    [_scroll release];
    [_userImage release];
    [_userSum release];
    [_userName release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createMyUser];
        [self createMyCell];
    }
    return self;
}
- (void)createMyUser
{
    self.userImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 40, 40)];
    _userImage.layer.cornerRadius = 20;
    _userImage.layer.masksToBounds = YES;
    [self.contentView addSubview:_userImage];
    [_userImage release];
    
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(50, 5, 300, 18)];
    _userName.font = [UIFont systemFontOfSize:14];
    _userName.textColor = [UIColor colorWithRed:102 / 255.0 green:153 / 255.0 blue:204 / 255.0 alpha:1];
    [self.contentView addSubview:_userName];
    [_userName release];
    
    self.userSum = [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 300, 18)];
    _userSum.font = [UIFont systemFontOfSize:12];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    _userSum.userInteractionEnabled = YES;
    [_userSum addGestureRecognizer:tap];
    [tap release];
    [self.contentView addSubview:_userSum];
    _userSum.textColor = [UIColor colorWithRed:216 / 255.0 green:33 / 255.0 blue:13 / 255.0 alpha:1];
    [_userSum release];
    
    self.label = [[UILabel alloc] initWithFrame:CGRectZero];
    _label.font = [UIFont systemFontOfSize:13];
    _label.numberOfLines = 0;
    [self.contentView addSubview:_label];
    [_label release];
    
    self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 80, 5, 80, 20)];
    [self addSubview:_dateLabel];
    [_dateLabel release];
    _dateLabel.font = [UIFont systemFontOfSize:12];
    _dateLabel.textColor = [UIColor lightGrayColor];
    
}


- (void)tapAction:(UITapGestureRecognizer *)sender
{
    self.labelBlock(_userSum.tag);
}
- (void)createMyCell
{
   
        
    
    self.buttomLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _buttomLabel.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:1];
    [self addSubview:_buttomLabel];
    [_buttomLabel release];
    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 48, [[UIScreen mainScreen] bounds].size.width - 20, 80)];
    
    [self.contentView addSubview:_scroll];
    [_scroll release];
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (_label.text.length == 0) {
        _scroll.frame = CGRectMake(10, 48, [[UIScreen mainScreen] bounds].size.width - 20, 80);
        self.buttomLabel.frame = CGRectMake(3, 131, [[UIScreen mainScreen] bounds].size.width - 6, 0.5);
    } else {
        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:13]};
        CGRect rect = [_label.text boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width - 20, 100000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        _label.frame = CGRectMake(10, 48, rect.size.width, rect.size.height);
        _scroll.frame = CGRectMake(10, 50 + rect.size.height, [[UIScreen mainScreen] bounds].size.width - 20, 80);
        
        self.buttomLabel.frame = CGRectMake(3, self.frame.size.height, [[UIScreen mainScreen] bounds].size.width - 6, 0.5);
    }
    
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
